package com.ninthgroup.benlailife.ui;

import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.RadioGroup;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.ninthgroup.benlailife.BaseApp;
import com.ninthgroup.benlailife.R;
import com.ninthgroup.benlailife.fragments.FestivalFragment;
import com.ninthgroup.benlailife.fragments.HomeFragment;
import com.ninthgroup.benlailife.fragments.KindFragment;
import com.ninthgroup.benlailife.fragments.MineFragment;
import com.ninthgroup.benlailife.utils.AppManager;
import com.ninthgroup.benlailife.utils.FragmentTabUtils;

import java.util.ArrayList;

public class MainActivity extends BaseActivity implements FragmentTabUtils.OnRgsExtraCheckedChangedListener{
    private long time;
    private ArrayList<Fragment> fragments=new ArrayList<>();
    @ViewInject(R.id.activity_main_footer_rgs)
    private RadioGroup radioGroup;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Fresco.initialize(this);
        setContentView(R.layout.activity_main);
        getSupportActionBar().hide();
        ViewUtils.inject(this);
        initView();
    }
    private void initView() {
        fragments.add(new HomeFragment());
        fragments.add(new KindFragment());
        fragments.add(new FestivalFragment());
        fragments.add(new MineFragment());
        new FragmentTabUtils(getSupportFragmentManager(),fragments,R.id.activity_main_fragment_container,radioGroup,this);

    }
    @Override
    public void onBackPressed() {
        long currentTime = System.currentTimeMillis();
        if (currentTime - time > 1000) {
            time = currentTime;
            BaseApp.getInstance().showToast(getString(R.string.app_exit_msg));
        } else {
            AppManager.getAppManager().AppExit(BaseApp.getInstance());
        }
    }

    @Override
    public void OnRgsExtraCheckedChanged(RadioGroup radioGroup, int checkedId, int index) {

    }
}
